<?php

declare(strict_types=1);

namespace App\Model\PssModel;

use App\Model\BaseModel\BasePssModel;

class Business extends BasePssModel
{
    protected $table = 'business';
    
    /**
     * 审核付款方式
     * @var unknown
     */
    public $afterVerifyMode = [
        '1' => '云仓审核付款方式',
        '2' => '渠道审核付款方式' 
    ];
    
    //指定写入字段
    protected $fillable = [
        
    ];
    
    //指定字段展示类型
    protected $casts = [
        'id' => 'string',
    ];
    /**
     * 用户类型
     * @var array
     */
    public $userType = [
        1 => '普通用户',
        2 => '会员',
    ];
    
    /**
     * 根据商户APPID 获取商户信息
     * @param array $param
     */
    public function getMerchantUserInfoByAppId( $appid = NULL ) 
    {   
        $info = $this->where('appid',$appid)
        ->select([
            'id as bid',
            'appid',
            'name',
            'secret',
            'open_url',
            'channel_id',
            'is_channel',
            'order_declare',
            'pay_declare',
            'user_source',
            'user_type',
            'user_level',
            'user_type',
            'user_tag',
            'total_balance_settlement_money',
            'settlement_warn_money',
            'template',
            'settlement',
            'template_price_tpl',
            'has_template',
            'is_market_price_send',
            'is_stock',
            'is_skip_declare',
            'is_skip_settlement',
            'is_router_user',
            'is_bbc_self_take',
            'account',
            'status',
            'is_support_aftersale_verify',
            'is_push_goods',
            'is_mult_shop',
            'user_tax_mode',
            'event_code',
            'is_order_package',
            'aftersale_verify_mode'
        ])
        ->first();
        
        if( empty($info) ) {
            return [];
        }
        
        return $info->toArray();
    }
    
    /**
     * 获取用户信息
     * @param number $bid
     */
    public function getUserInfoByBid( $bid = 0 )
    {
        $info = $this->where('id',$bid)
        ->select([
            'id',
            'id as bid',
            'name',
            'appid',
            'secret',
            'open_url',
            'channel_id',
            'is_channel',
            'order_declare',
            'user_source',
            'user_level',
            'user_type',
            'user_tag',
            'total_balance_settlement_money',
            'settlement_warn_money',
            'settlement',
            'is_market_price_send',
            'template',
            'sync_contents',
            'sync_mode',
            'sync_status',
            'pay_declare',
            'is_stock',
            'order_declare',
            'is_skip_declare',
            'is_skip_settlement',
            'is_router_user',
            'is_bbc_self_take',
            'yx_template_id',
            'hz_template_id',
            'account',
            'status',
            'is_support_aftersale_verify',
            'user_tax_mode',
            'event_code',
            'is_push_goods',
            'is_mult_shop',
            'is_order_package'
        ])
        ->first();
        if( empty($info) ) {
            return [];
        }
        
        return $info->toArray();
    }
    
    /**
     * 获取用户信息
     * @param number $bid
     */
    public function getUserInfoTemplatesByBids( $bids = [] )
    {
        return $this
        ->select([
            'id',
            'template',
            'is_channel',
            'is_router_user'
        ])
        ->whereIn('id',$bids)
        ->where('has_template',1)
        ->get()
        ->toArray();
    }
}